/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ds.tree.io;

import co.edu.unal.bioingenium.kbmed.config.Configuration;
import ds.tree.RadixTree;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 *
 * @author lariverosc
 */
public class PrefixIndexIO {


    /**
     * 
     *
     */
    public static void store(RadixTree prefixIndex, String name) throws IOException {
        File file = new File(Configuration.INDEX_DIR + File.separator + name);
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        objectOutputStream.writeObject(prefixIndex);
        objectOutputStream.close();
    }

    /**
     *
     *
     */
    public static RadixTree load(String name) throws IOException, ClassNotFoundException {
        FileInputStream fileInputStream = new FileInputStream(Configuration.INDEX_DIR + File.separator + name);
        ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
        RadixTree prefixIndex = (RadixTree) objectInputStream.readObject();
        objectInputStream.close();
        return prefixIndex;
    }

}
